<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 双指针法 */
            var longestPalindrome = function (s) {
                let res = 0
                let str = ''
                for (let i = 0; i < s.length; i++) {
                    let left = i - 1
                    let right = i + 1
                    let temp = 1
                    while (s[i] == s[left] && s[left]) {
                        left--
                        temp++
                    }
                    while (s[i] == s[right] && s[right]) {
                        right++
                        temp++
                    }
                    while (s[left] && s[right] && s[left] == s[right]) {
                        left--
                        right++
                        temp += 2
                    }
                    if (temp >= res) {
                        res = temp
                        str = s.substr(left + 1, temp)
                    }
                }
                return str
            }
        </script>
    </body>
</html>
